using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using OGAMRL.screens;
using OGAMRL.units;
using OGAMRL.Tiles;

namespace OGAMRL
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        #region Declarations
        //screens
        GameState gs;
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        World gameWorld;
        #endregion

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void Initialize()
        {
            gameWorld = new World(this.Content);
            //configure screens
            this.graphics.PreferredBackBufferWidth = 800;
            this.graphics.PreferredBackBufferHeight = 600;
            this.IsMouseVisible = true;
            Fonts.smallFont = Content.Load<SpriteFont>("fonts/smallfont");
            gs = new GameState(this.graphics.PreferredBackBufferHeight, this.graphics.PreferredBackBufferWidth, Fonts.smallFont);
            //set up fonts
            gs.setState(GameState.state.PLAYING);
            //set up the player character
            ObjectManager.player = new Player(Vector2.Zero, Content.Load<Texture2D>("gfx/BarbarianFighter3"), ref gs);
            GraphicsDevice.SamplerStates[0] = SamplerState.PointWrap;
            GraphicsDevice.BlendState = BlendState.AlphaBlend;
            this.graphics.ApplyChanges();
            base.Initialize();
        }
        protected override void LoadContent()
        {
        
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //loads the screen textures into an array and passes them to the game content manager
            Texture2D[] texArray = new Texture2D[2] {Content.Load<Texture2D>("gfx/ui/test_screen1"),
                                         Content.Load<Texture2D>("gfx/ui/test_screen2") };
            gs.setScreenTextures(texArray);
        }
        protected override void UnloadContent()
        {
          
        }
        protected override void Update(GameTime gameTime)
        {
            //get the player's input
            ObjectManager.player.readKeys(gameTime);
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            gs.currentScreen.drawScreen(ref spriteBatch);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
